#!/bin/bash
set -e

while getopts  ":s:p:" opts
do
	case  $opts  in
	s)
	barcode=$OPTARG
	sample_name=$OPTARG
	;;
	p)
	out_prefix=$OPTARG
	;;
	\?)
	echo cutadapt_brca12_ph.sh '[-p out_prefix] reads1.fq[.gz], reads2.fq[.gz]'
	exit 1
	;;
	esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then
	echo cutadapt_brca12_ph.sh '[-p out_prefix] reads1.fq[.gz], reads2.fq[.gz]'
	exit 1
fi

if [ -z $out_prefix ]; then
	out_prefix=1
fi

#-----------------------------------------------
#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------
#-----------------------------------------------

# log=.log
# if [ ! -e "$log" ]; then
	# :> $log
# fi

echo Sample name is: $barcode 2>>$log 1>&2
echo out prefix name is: $out_prefix 2>>$log 1>&2

# cutadapt=${tools_path}/cutadapt-1.8.1/bin/cutadapt

# truseq_uni=AATGATACGGCGACCACCGAGATCTACACTCTTTCCCTACACGACGCTCTTCCGATCT

# truseq_uni_res_com=AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATCTCGGTGGTCGCCGTATCATT

# truseq_uni_res_com_22=AGATCGGAAGAGCGTCGTGTAG
# truseq_uni_res_com_20=AGATCGGAAGAGCGTCGTGT

# truseq_0=GATCGGAAGAGCACACGTCTGAACTCCAGTCAC
# truseq_1=ATCTCGTATGCCGTCTTCTGCTTG

# truseq1=${truseq_0}${barcode}${truseq_1}

# truseq_0_22=GATCGGAAGAGCACACGTCTGA
# truseq_0_20=GATCGGAAGAGCACACGTCT

tem_seq1=TGGAATTCTCGGGTGCCAAG

tem_seq2=AGATCGGAAGAGCGTCGT

# primer5=$data_path/ref/b37/lunca50/primer5N.fa
# primer3=$data_path/ref/b37/lunca50/primer3N.fa


# s1=`basename $1 | cut -d . -f 1`
# s2=`basename $2 | cut -d . -f 1`

# if [ -n "$3" ]; then
	# s1=$3
# fi

# if [ -n "$4" ]; then
	# s1=$4
# fi



# $cutadapt \
# -n 2 \
# -q 10 \
# --trimmed-only \
# -m 65 \
# -M 200 \
# -a $truseq_0_20 \
# -A $truseq_uni_res_com_20 \
# -o $s1.cut.fastq \
# -p $s2.cut.fastq \
# $1 \
# $2 \
# 2>>$log 1>&2

# $cutadapt \
# -n 2 \
# -q 10 \
# -m 65 \
# -M 200 \
# -a $truseq_0_20 \
# -A $truseq_uni_res_com_20 \
# -o $s1.cut.fastq \
# -p $s2.cut.fastq \
# $1 \
# $2 \
# 2>>$log 1>&2


${tools_path}/Python-2.7.10/python \
$cutadapt \
-e 0.12 \
--overlap 4 \
-n 2 \
-m 56 \
-a $tem_seq1 \
-A $tem_seq2 \
-o $out_prefix.1.cut.fastq \
-p $out_prefix.2.cut.fastq \
$1 \
$2 \
2>>$log 1>&2

. $cmd_done

# --discard-untrimmed \


# $cutadapt \
# -e 0.13 \
# --discard-untrimmed \
# -a file:$primer3 \
# -A file:$primer3 \
# -g file:$primer5 \
# -G file:$primer5 \
# -o $out_prefix.1.trimmed.fastq \
# -p $out_prefix.2.trimmed.fastq \
# $out_prefix.1.cut.fastq \
# $out_prefix.2.cut.fastq \
# 2>>$log 1>&2

# -M 200 \

# $cutadapt \
# -u +20 \
# -u -20 \
# -U +20 \
# -U -20 \
# -m 20 \
# -o $s1.trimmed.fastq \
# -p $s2.trimmed.fastq \
# $s1.cut.fastq \
# $s2.cut.fastq \
# 2>>$log 1>&2

# len5=27
# len3=25

# $cutadapt \
# -u +$len5 \
# -u -$len3 \
# -U +$len5 \
# -U -$len3 \
# -o $out_prefix.1.trimmed.fastq \
# -p $out_prefix.2.trimmed.fastq \
# $out_prefix.1.cut.fastq \
# $out_prefix.2.cut.fastq \
# 2>>$log 1>&2


# seqtk trimfq -b $len5 $out_prefix.1.cut.fastq > $out_prefix.1.trimmed.fastq
# seqtk trimfq -b $len5 $out_prefix.2.cut.fastq > $out_prefix.2.trimmed.fastq
